package com.hqyj.system.controller;

import com.hqyj.system.model.Custom;
import com.hqyj.system.model.productInformation;
import com.hqyj.system.service.ProductInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/productInformationController")
public class ProductInformationController {

    @Autowired
    private ProductInformationService productInformationService;

    @RequestMapping("/list.do")
    public String List(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, productInformation productInformation) {
        //1.接收数据;
        System.out.println("=====productInformationController=======list()====");
        //3.调用业务;
        List<productInformation> productInformation_dbList = productInformationService.queryAllProductInformation();
//        for (productInformation productInformation1:productInformation_dbList){
//            System.out.println("=====productInformationController=======list()====" + productInformation1);
//        }
        //返回数据
        model.addAttribute("productInformation_dbList", productInformation_dbList);
        //2.跳转页面;
        return "h5/productInformation-list";
    }

    @RequestMapping("/add.do")
    public String add(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, productInformation productInformation) {
        //1.接收数据;
        System.out.println("====productInformationController=======add=========" + productInformation);
        //3.调用业务;
        int n  = productInformationService.addProductInformationBy(productInformation);

        //2.跳转页面;
        //查询产品信息
        List<productInformation> productInformation_dbList = productInformationService.queryAllProductInformation();
        //返回数据
        model.addAttribute("productInformation_dbList", productInformation_dbList);
        //2.跳转页面;
        return "h5/productInformation-list";
    }

    @RequestMapping("/updateUI.do")
    public String updateUI(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model,productInformation productInformation, String productIdStr){
        //1.接收数据;
        System.out.println("=============================="+ productIdStr);
        //字符类型转成数字类型
//        int customId = Integer.parseInt(customIdStr);
        //3.调用业务;
//        Custom custom_db = customService.queryCustomByCustomId(customId);
//        model.addAttribute("custom_db", custom_db);
        //2.跳转页面;
        return "h5/updateProductInformation";
    }


}